package com.loveazure.ui;

import java.awt.Toolkit;

import javax.swing.JFrame;

public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8687062548713600743L;

	private IPanel loginPanel;
	private IPanel studyPanel;
	private IPanel configPanel;
	private IPanel coursePanel;

	public enum Status {
		LOGIN, STUDY, CONFIG, COURSE
	}

	private IPanel currentPanel;

	public MainFrame() {
		iLayout();
	}

	public void iLayout() {
		setTitle("JPowerWord");
		setSize(320 + 16, 320 + 38);
		// setResizable(false);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setIconImage(Toolkit.getDefaultToolkit().getImage("images//logo.png"));
	}

	public void iMenubar() {
		// TODO Auto-generated method stub
	}

	public void switchPanel(Status status) {
		if (currentPanel != null) {
			remove(currentPanel);
		}
		switch (status) {
		case LOGIN:
			if (loginPanel == null) {
				loginPanel = new LoginPanel();
			}
			currentPanel = loginPanel;
			break;
		case STUDY:
			if (studyPanel == null) {
				studyPanel = new LearnPanel();
			}
			currentPanel = studyPanel;
			break;
		case CONFIG:
			if (configPanel == null) {
				configPanel = new ConfigPanel();
			}
			currentPanel = configPanel;
			break;
		case COURSE:
			if (coursePanel == null) {
				coursePanel = new CoursePanel();
			}
			currentPanel = coursePanel;
			break;
		default:
			break;
		}
		currentPanel.iInit();
		add(currentPanel);
		validate();
		repaint();
		currentPanel.requestFocus();
	}
}
